package com.erb.service.zwj.impl;

import com.erb.entity.Pager;
import com.erb.entity.Type;
import com.erb.mapper.TypeMapper;
import com.erb.service.zwj.ITypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service("typeService")
public class TypeServiceImpl implements ITypeService {
	@Resource
	private TypeMapper typeMapper;

	/**
	 * 查询所有类型
	 *
	 * @return
	 */
	@Override
	public List<Type> findAll(Pager pager) {
		if (null == pager) {
			return typeMapper.selectAll(null);
		}
		return typeMapper.selectAll(pager);
	}

	@Override
	public long findCount() {
		return typeMapper.selectCount();
	}

	/**
	 * 保存类型
	 *
	 * @param type
	 * @return
	 */
	@Override
	public boolean saveType(Type type) {
		if (null == type) {
			return false;
		}

		return typeMapper.insertType(type) > 0;
	}

	@Override
	public Type findTypeById(Long id) {
		if (null == id || id <= 0) {
			return null;
		}

		return typeMapper.selectTypeById(id);
	}

	@Override
	public boolean removeType(Long id) {
		if (null == id || id <= 0) {
			return false;
		}

		return typeMapper.deleteType(id) > 0;
	}

	@Override
	public boolean editType(Type type) {
		if (null == type) {
			return false;
		}

		return typeMapper.updateType(type) > 0;
	}

	@Override
	public boolean findTypeByEqName(String typeName) {
		if (null == typeName) {
			return false;
		}

		return typeMapper.selectTypeByEqName(typeName) != null;
	}
}
